import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pizza_test/const/const.dart';
import 'package:pizza_test/model/chefmodel.dart';
import 'package:pizza_test/screen/view/pizz_property_view.dart';
import 'package:pizza_test/screen/view/pizza_to_other_view.dart';

class PizzaList extends StatelessWidget {

  final Pizza p;
  final ChefColors pColor;
  final Function(String chefName, Pizza p) changePizzaToOtherAction;
  PizzaList(this.p,this.pColor, this.changePizzaToOtherAction);

  Widget _createTextWidget(String title) {
    return Text(
      title,
      style: TextStyle(
        fontSize: 10,
      ),
    );
  }

  showMore(BuildContext context){
    showDialog(
      context: context,
      barrierDismissible: false,
      builder: (context) {
        return PizzPropertyView(
          pizza: p, 
          pizzaSizeAction: (EpizzaSize size){
            p.size = size;
          },
          chooseOtherAction: (String other){
            if(p.toppings.contains(other)){
              p.toppings.remove(other);
            } else {
              p.toppings.add(other);
            }
          },
      );
      }
    );
  }

  showChefs(BuildContext context) {
    showDialog(
      context: context,
      barrierDismissible: true,
      builder: (context) {
        return PizzaToOtherChefView(changePizzaToOtherAction: (String name){
          changePizzaToOtherAction(name, p);
        });
      }
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 5,vertical: 4),
      child: Wrap(
          direction: Axis.horizontal,
          alignment: WrapAlignment.spaceBetween,
          children: <Widget>[
            Container(
              padding: const EdgeInsets.all(2),
              // margin: const EdgeInsets.symmetric(vertical: 10),
              color: pColor.backColor,
              child: Text(
                "PIZZA ${p.pizzaId}",
                style: TextStyle(color: pColor.textColor, fontSize: 9, fontWeight: FontWeight.bold),
              )
            ),
            SizedBox(width: 4),
            GestureDetector(
              onTap: (){
                showMore(context);
              },
              child: _createTextWidget("[Edit]"),
            ),
            GestureDetector(
              onTap: (){
                showChefs(context);
              },
              child: _createTextWidget("[Delega]"),
            )
          ],
        ),
    );
  }
}